#include<iostream>
using namespace std;
const int N=110;
int T;
int n;
int a[N],c[N];
inline int check()
{
    int ret=0;
    for(int i=1;i<=n;i++)
    {
        int flag=-1;
        for(int j=i-1;j>=1;j--)
        {
            if(c[j]==c[i]){flag=a[j];break;}
        }
        if(flag==a[i])ret+=a[i];
    }
    return ret;
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--)
    {
        cin>>n;
        int ans=0;
        for(int i=1;i<=n;i++)cin>>a[i];
        for(int i=0;i<(1<<n);i++)
        {
            for(int j=0;j<n;j++)
            {
                c[j+1]=i&(1<<j);
            }
            ans=max(ans,check());
        }
        cout<<ans<<endl;
    }
    return 0;
}
